﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Configuration;
using KandaAlpha.Application.Interfaces;
using KandaAlpha.UI.Mvc.Infrastructure.Mvc;
using KandaAlpha.UI.Mvc.Infrastructure.Ioc;
using KandaAlpha.UI.Mvc.Controllers;
using Microsoft.Practices.ServiceLocation;
using KandaAlpha.Infrastructure.Repository.db4o;
namespace KandaAlpha.UI.Mvc
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default",                                              // Route name
                "{controller}/{action}/{id}",                           // URL with parameters
                new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
            );

        }

        protected void Application_Start()
        {

            RegisterRoutes(RouteTable.Routes);

            // configure inversion of control
            IocBootstrapper.Initialise();

            // set ioc controller factory
            ControllerBuilder.Current.SetControllerFactory(new IoCControllerFactory());
        }

        protected void Application_End()
        {
            // TODO - put behind an application level facade
            ServiceLocator.Current.GetInstance<KandaAlpha.Infrastructure.Repository.db4o.IObjectContainerManager>().CloseServer();
        }


    }
} 